home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 395_01 / typing / source / dolesson.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-19  |  2.6 KB  |  123 lines

  1. /* #ident "@(#)do_lesson.c - The text and window handling routines." */
  2.  
  3. #include "tt.h"
  4. #include "externals.h"
  5.  
  6. do_lesson()
  7. {
  8.   int x, y, get_the_data = FALSE, no_of_data_lines = 0;
  9.   void get_data (), paktc ();
  10.   static int first_time = TRUE;
  11.  
  12.   while ( !feof ( lesson ))
  13.   {
  14.     fgets ( ipbuffer, COLS-2, lesson );
  15.     ipbp = ipbuffer;
  16.     no_of_data_lines++;
  17.     x = TEXT_LEFT_SIDE;
  18.  
  19.     if ( ipbuffer[1] == '\n' )
  20.     {                        /* A single flag character line in lesson file. */
  21.       y = TEXT_TOP_LINE;
  22.       if ( !first_time )
  23.       {
  24.         border ( current_window );
  25.         wnoutrefresh ( current_window );
  26.         doupdate();
  27.     }
  28.       if ( current_window == middle_window )
  29.       {
  30.         border ( bottom_window );
  31.         wnoutrefresh ( bottom_window );
  32.         doupdate();
  33.     }
  34.  
  35.       if ( get_the_data ) get_data (--no_of_data_lines);
  36.  
  37.       switch ( ipbuffer[0] )                 /* Is it a line of instructions */
  38.       {                             /*    or data to be copied by the student? */
  39.  
  40. case INSTRUCTION_FLAG:
  41. {
  42.       if ( !first_time && !get_the_data )
  43.       { paktc ();                           /* Press Any Key To Continue. */
  44.         break;
  45.         }
  46.       current_window = top_window;
  47.           get_the_data = FALSE;
  48.           break;
  49.       }
  50.  
  51. case DATA_FLAG:
  52.         { get_the_data = TRUE;
  53.       current_window = middle_window;
  54.       no_of_data_lines = 0;
  55.       werase ( bottom_window );
  56.           break;
  57.       }                                        /* End of DATA case. */
  58.         }                                         /* End of switch statement. */
  59.  
  60.       first_time = FALSE;
  61.       werase ( current_window );
  62.       continue;
  63.       }                                      /* end of flag character block. */
  64.       else
  65.     {                            /* there is a line of text from lesson file. */
  66.       wattrset ( current_window, 0 );
  67.       mvwaddstr ( current_window, y, x, ipbuffer );
  68.       if ( current_window == middle_window )
  69.       {
  70.         wattrset ( bottom_window, 0 );
  71.     wmove ( bottom_window, y, x );
  72.         while ( *ipbp != '\n' )
  73.         {
  74.       waddch ( bottom_window, ( *ipbp == SPACE ) ? SPACE : UNDERLINE );
  75.       ipbp++;
  76.       }
  77.         }
  78.       y++;
  79.       }
  80.     }
  81.   }
  82.  
  83. /*
  84.  * paktc (); - Press A Key To Continue.
  85.  */
  86.  
  87. #define PAKTC_WINDOW_HEIGHT 3
  88. #define PAKTC_WINDOW_WIDTH 30
  89. #define PAKTC_WINDOW_ROW 21
  90.  
  91. char *paktc_message = {"Press Any Key To Continue."};
  92.  
  93. void paktc ()
  94. {
  95.   WINDOW *paktc_window;
  96.   char junk_char;
  97.   int row, column, paktc_window_column;
  98.  
  99.   row = 1;
  100.   column = 2;
  101.   paktc_window_column = ( COLS - PAKTC_WINDOW_WIDTH ) / 2;
  102.  
  103.   paktc_window = newwin ( PAKTC_WINDOW_HEIGHT,
  104.                           PAKTC_WINDOW_WIDTH,
  105.               PAKTC_WINDOW_ROW,
  106.               paktc_window_column
  107.               );
  108.  
  109.   werase ( paktc_window );
  110.   wmove ( paktc_window, row, column );
  111.   wprintw ( paktc_window, "%s", paktc_message );
  112.   wnoutrefresh ( paktc_window );
  113.   border ( paktc_window );
  114.   wnoutrefresh ( paktc_window );
  115.   doupdate ();
  116.   junk_char = getch ();
  117.   werase ( paktc_window );
  118.   wnoutrefresh ( paktc_window );
  119.   doupdate ();
  120.   delwin ( paktc_window );
  121.   }
  122.  
  123.